<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title data-i18n="resources.title_heatMapLayer"></title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            width: 300px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.text_fastHeatMapLayer"></h5></div>
    <div class='panel-body content'>
        <div class='panel'>
            <div class='input-group'>
                <span class='input-group-addon' data-i18n="resources.text_countsDraw"></span>
                <input type='text' class='form-control' id='heatNums' value='200'/>
            </div>
        </div>
        <div class='panel'>
            <div class='input-group'>
                <span class='input-group-addon' data-i18n="resources.text_radius"></span>
                <input class='form-control' style='width: 50px' value='50' id='heatradius'/>
                <select class='form-control' style='width:auto' id='radiusUnit'>
                    <option value='px'>px</option>
                    <option data-i18n='[value]resources.text_degree;resources.text_degree'></option>
                </select>
            </div>
        </div>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_startDraw"
               onclick="createHeatPoints()"/>&nbsp; &nbsp;
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear"
               onclick="clearHeatPoints()"/>
    </div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
<script type="text/javascript" src="../../dist/maplibregl/include-maplibregl.js"></script>
<script type="text/javascript">
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var map, heatMapLayer,
        url = host + "/iserver/services/map-world/rest/maps/World";
    var attribution = "<a href='https://www.maplibre.com/about/maps/' target='_blank'>© MapLibre </a>" +
            " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
            " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";

    var map = new maplibregl.Map({
        container: 'map',
        renderWorldCopies:false,
        style: {
            "version": 8,
            "sources": {
                "raster-tiles": {
                    "attribution": attribution,
                    "type": "raster",
                    "tiles": [url + '/zxyTileImage.png?z={z}&x={x}&y={y}'],
                    "tileSize": 256,
                },
            },
            "layers": [{
                "id": "simple-tiles",
                "type": "raster",
                "source": "raster-tiles",
                "minzoom": 0,
                "maxzoom": 9
            }]
        },
        center: [0, 0],
        zoom: 1
    });
    map.addControl(new maplibregl.NavigationControl(), 'top-left');
    map.addControl(new maplibregl.supermap.LogoControl({ link: "https://iclient.supermap.io" }), 'bottom-right');

    heatMapLayer = new maplibregl.supermap.HeatMapLayer(
        "heatMap",
        {
            "map": map,
            "id": "heatmap",
            "radius": 45,
//            设置图层透明度：（参数方式）
//            "opacity": 0.5,
            //featureWeight指定以哪个属性值为热力权重值创建热力图：
            "featureWeight": "value",
        }
    );

    function createHeatPoints() {
        clearHeatPoints();
        var heatPoints = [];
        var num = parseInt(document.getElementById('heatNums').value);
        var radius = parseInt(document.getElementById('heatradius').value);
        var unit = document.getElementById("radiusUnit").value;
        //resources.text_degree 表示 id=radiusUnit 选项的第一选项值
        if (resources.text_degree == unit) {
            //热力半径单位使用地理单位
            heatMapLayer.useGeoUnit = true;
        } else {
            //热力半径单位不使用用地理单位
            heatMapLayer.useGeoUnit = false;
        }
        heatMapLayer.radius = radius;

        var features = [];

        for (var i = 0; i < num; i++) {

            features[i] =
                {
                    "type": "feature",
                    "geometry": {
                        "type": "Point",
                        "coordinates": [
                            Math.random() * 360 - 180,
                            Math.random() * 160 - 80]
                    },
                    "properties": {
                        "value": Math.random() * 9,
                    }
                };
        }

        var heatPoints = {
            "type": "FeatureCollection",
            "features": features
        };

        heatMapLayer.addFeatures(heatPoints);
//        设置图层透明度：（函数方式）
//        heatMapLayer.setOpacity(0.5);
        map.addLayer(heatMapLayer);
    }

    function clearHeatPoints() {
        if (map.getLayer("heatmap")) {
            map.removeLayer("heatmap");
        }
    }
</script>
</body>
</html>